//
//  LGJoinProjectHeaderView.m
//  HeartDisease_YHJK
//
//  Created by 1234 on 2025/10/27.
//  配置量表 -- 区头

#import "LGJoinProjectHeaderView.h"

@interface LGJoinProjectHeaderView()
/**   */
@property (nonatomic , strong)UIButton *iconButton;
/**   */
@property (nonatomic , strong)UILabel *titleLabel;

@end

@implementation LGJoinProjectHeaderView
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubview:self.titleLabel];
        [self addSubview:self.iconButton];
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(viewPix(42));
            make.right.equalTo(self).offset(-viewPix(12));
            make.centerY.equalTo(self);
        }];
        [self.iconButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.bottom.right.equalTo(self);
        }];
    }
    return self;
}

-(void)setIndex:(NSInteger)index{
    _index = index;
}

-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    self.titleLabel.text = LGNSString(dataDic[@"title"]);
    NSArray *tempArray = dataDic[@"lists"];
    BOOL select = NO;
    for (NSDictionary *tempDic in tempArray) {
        NSString *checked = LGNSString(tempDic[@"is_checked"]);
        if ([checked isEqualToString:@"1"]) {
            select = YES;
            break;
        }
    }
    self.iconButton.selected = select;
}

-(void)iconButtonAction:(UIButton *)sender{
    sender.selected = !sender.selected;
    if (self.sectionSelectAction) {
        self.sectionSelectAction(sender.selected, self.index);
    }
}

-(UIButton *)iconButton{
    if(!_iconButton){
        _iconButton = [UIButton buttonWithImage:@"unselect24" selectImage:@"selected24"];
        _iconButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        _iconButton.imageEdgeInsets = UIEdgeInsetsMake(0, viewPix(14), 0, 0);
        [_iconButton addTarget:self action:@selector(iconButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _iconButton;
}

-(UILabel *)titleLabel{
    if(!_titleLabel){
        _titleLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFontWeight(18, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:0];
    }
    return _titleLabel;
}

@end
